
const { baseUrl } = require('./env').prod

module.exports = {
  request : function(url, data = {},method = 'GET',){
    let fullUrl = `${baseUrl}${url}`
    return new Promise((resolve,reject)=>{
      wx.request({
        url: fullUrl,
        method,
        data,
        header:{
          'content-type': 'application/json',
          'X-Mymall-Token':wx.getStorageSync('token')
        },
        success(res){
          if (res.statusCode == '200') {
            resolve(res.data)
          }else{
            wx.showToast({
              title: res.data.errmsg,
              icon:'none'
            })
            reject(res.data.message)
          }
        },
        fail(res){
          console.log(res);
          wx.showToast({
            title: '接口请求错误',
            icon:'none'
          })
          reject('接口请求错误')
        }
      })
    })
  }
}
